package com.bingfor.sharedemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.bingfor.sharedemo.databinding.ActivitySingleShareBinding;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

public class SingleShareActivity extends AppCompatActivity {

    ActivitySingleShareBinding binding ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySingleShareBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initView();
    }
    private void initView(){
        binding.btSinaShare.setOnClickListener(v -> {
            UMImage image = new UMImage(SingleShareActivity.this, "http://img.xmpig.com/forum/201610/20/201816z4zvp3zov8vtpp5g.jpg");//网络图片
            new ShareAction(SingleShareActivity.this)
                    .setPlatform(SHARE_MEDIA.SINA)
                    .withText("test")
                    .withMedia(image)
                    .setCallback(umShareListener).share();
        });
        binding.btQqShare.setOnClickListener(v -> {
            UMImage image = new UMImage(SingleShareActivity.this, "http://img.xmpig.com/forum/201610/20/201816z4zvp3zov8vtpp5g.jpg");//网络图片
            new ShareAction(SingleShareActivity.this)
                    .setPlatform(SHARE_MEDIA.QQ)
                    .withText("test")
                    .withMedia(image)
                    .setCallback(umShareListener).share();
        });
        binding.btQqZoneShare.setOnClickListener(v -> {
            UMImage image = new UMImage(SingleShareActivity.this, "http://img.xmpig.com/forum/201610/20/201816z4zvp3zov8vtpp5g.jpg");//网络图片
            new ShareAction(SingleShareActivity.this)
                    .setPlatform(SHARE_MEDIA.QZONE)
                    .withText("test")
                    .withMedia(image)
                    .setCallback(umShareListener).share();
        });
        binding.btWeixinShare.setOnClickListener(v -> {
            UMImage image = new UMImage(SingleShareActivity.this, "http://img.xmpig.com/forum/201610/20/201816z4zvp3zov8vtpp5g.jpg");//网络图片
            new ShareAction(SingleShareActivity.this)
                    .setPlatform(SHARE_MEDIA.WEIXIN)
                    .withText("test")
                    .withMedia(image)
                    .setCallback(umShareListener).share();
        });
        binding.btWeixinCircleShare.setOnClickListener(v -> {
            UMImage image = new UMImage(SingleShareActivity.this, "http://img.xmpig.com/forum/201610/20/201816z4zvp3zov8vtpp5g.jpg");//网络图片
            new ShareAction(SingleShareActivity.this)
                    .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)
                    .withText("test")
                    .withMedia(image)
                    .setCallback(umShareListener).share();
        });

    }
    UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {
            Toast.makeText(SingleShareActivity.this,"start",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onResult(SHARE_MEDIA share_media) {
            Toast.makeText(SingleShareActivity.this,"success",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(SHARE_MEDIA share_media, Throwable throwable) {
            Toast.makeText(SingleShareActivity.this,"onError",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA share_media) {
            Toast.makeText(SingleShareActivity.this,"onCancel",Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

    }
}
